package com.jinlejia.bbs.logic;

import android.content.Context;

import com.jinlejia.bbs.http.utils.BBSConfig;
import com.jinlejia.bbs.http.utils.HttpCallBack;

import static com.jinlejia.bbs.http.utils.HttpUtils.JsonParse;
import static com.jinlejia.bbs.http.utils.HttpUtils.httpCall;
import static com.jinlejia.bbs.http.utils.HttpUtils.httpCallBack;
/**
 * @author 王进 on 2019/3/29.
 */
//关注 取消关注
public class TakeAttentionLogic {
    private Context context;
    public TakeAttentionLogic(Context context){
        this.context = context;
    }

    public void execute(String pin, final LogicCallBack callBack){
        httpCall(BBSConfig.takeAttention.concat(pin))
                .execute(httpCallBack(context, new HttpCallBack() {
                    @Override
                    public void onError(Exception e) {

                    }

                    @Override
                    public void onResponse(JsonParse parse) {
                        int state = parse.parse(Integer.class);
                        System.out.println("------------->请求了("+state+")");
//                        0:未关注 1：已关注 2：互相关注
                        if (state==1){ //未关注
                            callBack.onResult(0);
                        }else if (state==2){ //取消关注
                            callBack.onResult(1);
                        }else if (state==3){ //互相关注
                            callBack.onResult(2);
                        }
                    }

                    @Override
                    public void onNoResponse(int code) {

                    }
                }));
    }

    public interface LogicCallBack{
        void onResult(int result);
    }
}
